package com.hqj.demo.dao;

import com.hqj.demo.entity.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserDaoI implements UserDao{

    private static SqlSession ss;

    static{
        String resource = "resource/mybatis-config.xml";
        try {
            //读取本地配置文件
            InputStream is = Resources.getResourceAsStream(resource);
            SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(is);
            ss = ssf.openSession();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @Override
    public List<User> findUser() {
        List<User> list = ss.selectList("findUsers");
        return list;
    }

    @Override
    public List<User> getUser(User u) {
        List<User> list = ss.selectList("getUsers",u);
        return list;
    }

    public void test123(){

    }
}
